<template>
  <div>
    <el-form label-position="right" label-width="80px" ref="form" :rules="rules" :model="form">
      <el-form-item label="礼品名称" prop="name">
        <el-input v-model="form.name" :disabled="true" placeholder="请输入礼品名称"></el-input>
      </el-form-item>
      <el-form-item label="礼品数量" prop="num">
        <el-input v-model="form.num" type="number" placeholder="请输入礼品数量"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="msg">
        <el-input v-model="form.msg" type="textarea" placeholder="请输入备注"></el-input>
      </el-form-item>
      <el-form-item class="contacts-add">
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="cancle">关闭</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import * as APIIntegral from '@/api/integral'
export default {
  name: 'goods-ruku',
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      form: {},
      dialogVisible: false,
      // 表单校验
      rules: {
        num: [
          {
            required: true,
            message: '请输入礼品数量',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    // 入库
    onSubmit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          APIIntegral.integralRu(this.form).then(res => {
            this.$message({ type: "success", message: "入库成功!"});
            this.cancle()
            this.load()
          })
        }
      })
    },
    load () {
      this.$emit('load')
    },
    cancle () {
      this.$refs.form.resetFields()
      this.$emit('cancle')
    }
  },
  watch: {
    data: {
      handler (newval) {
        this.form = newval
      },
      // 可以一进页面就触发监听器  监听器自带的immediate
      immediate: true,
      deep: true
    }
  }
}
</script>

<style lang="scss">
</style>
